#ifndef __BASE_LOG_H
#define __BASE_LOG_H
#include <fstream>
#include <queue>
#include <mutex>
#include <thread>
#include <rtc_base/logging.h>
namespace xrtc
{

    class XrtcLog : public rtc::LogSink
    {
    public:
        XrtcLog(const std::string &log_dir,
                const std::string &log_name,
                const std::string &log_level);
        ~XrtcLog() override;
        int init();
        bool start();
        void stop();
        void join();
        void set_log_to_stderr(bool on);
        void OnLogMessage(const std::string &message, rtc::LoggingSeverity severity) override;
        void OnLogMessage(const std::string &message) override;

    private:
        std::string _log_dir;
        std::string _log_name;
        std::string _log_level;

        std::string _log_file;
        std::string _log_file_wf;

        std::ofstream _out_file;
        std::ofstream _out_file_wf;

        //日志队列
        std::queue<std::string> _log_queue;
        std::mutex _mtx;
         std::queue<std::string> _log_queue_wf;
        std::mutex _mtx_wf;

        std::thread *_thread = nullptr;
        std::atomic<bool> _running;
    };

}

#endif //__BASE_LOG_H